package com.huaqin.customer.expansion;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.telephony.TelephonyManager;
//import android.os.SystemProperties;
import android.util.Log;

public class MessageItem {
	
	private static final String TAG = "MessageManager";
	//private Context mContext;

	public static final String SALES_TRACKER_PARAM_NONE = "none";
	public static final String SALES_TRACKER_PARAM_MODEL_NAME = "model_name";
	public static final String SALES_TRACKER_PARAM_IMEI = "imei";
	public static final String SALES_TRACKER_PARAM_IMSI = "imsi";
	public static final String SALES_TRACKER_PARAM_HOME_PLMN = "home_plmn";
	public static final String SALES_TRACKER_PARAM_PLMN = "plmn";
	public static final String SALES_TRACKER_PARAM_ICCID = "iccid";
	public static final String SALES_TRACKER_PARAM_CELLID = "cellid";
	public static final String SALES_TRACKER_PARAM_LAC = "lac";
	public static final String SALES_TRACKER_PARAM_SWVER = "swver";
	public static final String SALES_TRACKER_PARAM_HWVER = "hwver";
	public static final String SALES_TRACKER_PARAM_IMEI1_ONLY = "imei1_only"; // 所有IMEI 都获取
	public static final String SALES_TRACKER_PARAM_IMEI2_ONLY = "imei2_only";
	public static final String SALES_TRACKER_PARAM_SCNUM = "scnum"; //Echo SMS Center Num
	public static final String SALES_TRACKER_PARAM_CUSTOM = "custrom";
	private TelephonyManager telephonyManager;
	
	public static final int GEMINI_SIM_1 = 0; //Math MessageManager.java SIMId
	public static final int GEMINI_SIM_2 = 1;
	
	public MessageItem(Context context){
		telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE );
	}

	public String getItemValues(String itemKey){

		if(SALES_TRACKER_PARAM_MODEL_NAME.equals(itemKey)){
			return getModelName();
		}
		else if(SALES_TRACKER_PARAM_IMEI.equals(itemKey)){
			return getIMEIId();
		}
		else if(SALES_TRACKER_PARAM_IMSI.equals(itemKey)){
			return getIMSIId();
		}
		else if(SALES_TRACKER_PARAM_HOME_PLMN.equals(itemKey)){
			return getHomePlmn();
		}
		else if(SALES_TRACKER_PARAM_PLMN.equals(itemKey)){
			return null;
		}
		else if(SALES_TRACKER_PARAM_ICCID.equals(itemKey)){
			return null;
		}
		else if(SALES_TRACKER_PARAM_CELLID.equals(itemKey)){
			 //cellLocation.getCid();
			return null;
		}
		else if(SALES_TRACKER_PARAM_LAC.equals(itemKey)){
			return null;
		}
		else if(SALES_TRACKER_PARAM_SWVER.equals(itemKey)){
			return getSWVersion();
		}
		else if(SALES_TRACKER_PARAM_HWVER.equals(itemKey)){
			return getHWVerrsion();
		}
		else if(SALES_TRACKER_PARAM_IMEI1_ONLY.equals(itemKey)){
			return getIMEI1();
		}
		else if(SALES_TRACKER_PARAM_IMEI2_ONLY.equals(itemKey)){
			return getIMEI2();
		}
		else if(SALES_TRACKER_PARAM_SCNUM.equals(itemKey)){
			return null;
		}
		else if(SALES_TRACKER_PARAM_CUSTOM.equals(itemKey)){
			return null;
		}
		//Add unkonwn item to following
//		else if(){
//			......
//		}
		else{
			Log.e(TAG, "Unkonw itme:[" + itemKey + "]");
			return null;
		}

	}
	
	@SuppressLint("DefaultLocale")
	private String getModelName(){
	    return Build.MODEL.toUpperCase();
	}
	
	private String getIMEIId(){
		return telephonyManager.getDeviceId();
	}
	
	private String getIMSIId(){
		return telephonyManager.getSubscriberId();
	}
	
	//MCC + MNC = IMSI
	private String getMccMNC(){
		return telephonyManager.getNetworkOperator();
	}
	
	private String getHomePlmn(){
		return null;
	}

	private String getPlmn(){
		return null;
	}
	
	private String getMCCMNC() {
		return telephonyManager.getSimOperator();
	}

	private String getIMSI() {
		return telephonyManager.getSubscriberId();
	}
	
	
//	protected String get(){
//		int cell_id = CellLocation.getCid();      //小区识别码
//	    return Integer.toHexString(cell_id);   //转换为十六进制
//
//	}
	
	@SuppressLint("DefaultLocale")
	private String getHWVerrsion(){
		return Build.HARDWARE.toUpperCase();
	}
	

	@SuppressLint("DefaultLocale")
	private String getSWVersion(){
		return Build.DISPLAY.toUpperCase();
	}
	
	private String getICCID(){
		return telephonyManager .getSimSerialNumber();
	}
	
	private String getHuaQinSWVersion(){
		//return SystemProperties.get( "ro.build.hq.sw.version"); //Huaqin nxl
		return "huaqin";
	}
	
	private String getIMEI1(){
		//return telephonyManager.getDeviceIdGemini(GEMINI_SIM_1); //MTK nxl
	    return "imsi1";
	}
	
	private String getIMEI2(){
		//return telephonyManager.getDeviceIdGemini(GEMINI_SIM_2); //MTK nxl
		return "imsi2";
	}
	
	private String getPhoneNumer(){
		return telephonyManager.getLine1Number();
	}

	private String getNetworkOperatorName(){
		return telephonyManager.getNetworkOperatorName();
	}
	
	
	
	
	
	
}
